#include "WelcomeScene.h"
#include "SimpleAudioEngine.h"
#include "AboutScene.h"
#include "GameScene.h"
#include "SettingsScene.h"
#include "SoundSettings.h"
using namespace cocos2d;
using namespace CocosDenshion;

CCScene* Welcome::scene() {
	// 'scene' is an autorelease object
	CCScene *scene = CCScene::create();

	// 'layer' is an autorelease object
	Welcome *layer = Welcome::create();

	// add layer as a child to scene
	scene->addChild(layer);

	// return the scene
	return scene;
}

// on "init" you need to initialize your instance
bool Welcome::init() {
	if (!CCLayer::init()) {
		return false;
	}
	CCMenuItemLabel *it0 = CCMenuItemLabel::create(CCLabelTTF::create("Play", "Thonburi", 34), this,menu_selector(Welcome::runGame));
	CCMenuItemLabel *it1 = CCMenuItemLabel::create(CCLabelTTF::create("Settings", "Thonburi", 34), this,menu_selector(Welcome::runSettings));
	CCMenuItemLabel *it2 = CCMenuItemLabel::create(CCLabelTTF::create("About", "Thonburi", 34), this,menu_selector(Welcome::runAbout));
	CCMenuItemLabel *it3 = CCMenuItemLabel::create(CCLabelTTF::create("Close", "Thonburi", 34), this,menu_selector(Welcome::menuCloseCallback));
	CCMenu* pMenu = CCMenu::create(it0, it1, it2, it3, NULL);
	pMenu->alignItemsVertically();
	this->addChild(pMenu);
	playBackground();
	return true;
}

void Welcome::menuCloseCallback(CCObject* pSender) {
	CCDirector::sharedDirector()->end();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
	exit(0);
#endif
}

void Welcome::runGame(CCObject* sender) {
	 CCScene *pScene = GameScene::scene();
	 CCDirector::sharedDirector()->replaceScene(pScene);
}

void Welcome::runSettings(CCObject* sender) {
	 CCScene *pScene = Settings::scene();
	 CCDirector::sharedDirector()->replaceScene(pScene);
}

void Welcome::runAbout(CCObject* sender) {
	 CCScene *pScene = AboutScene::scene();
	 CCDirector::sharedDirector()->replaceScene(pScene);
}
